import re
import matplotlib.pyplot as plt
pattern = re.compile(r'\^\&[0-9]+')
reviewNum=[]
partNum=[]

print("请输入回复数量饼图范围，以空格间隔")
reviewRange=input().split()
for i in range(len(reviewRange)-1):
    reviewNum.append(0)
    
print("请输入参与数量饼图范围，以空格间隔")
partRange=input().split()
for i in range(len(partRange)-1):
    partNum.append(0)
    
with open('data.txt','r',encoding='utf-8') as f:
    for  i in f.readlines():
        str=i.strip()
        if len(pattern.findall(str))>2:
            a=int(pattern.findall(str)[1][2:])
            b=int(pattern.findall(str)[2][2:])
            for i in range(len(reviewRange)-1):
                if int(reviewRange[i])<a<int(reviewRange[i+1]):
                    reviewNum[i]+=1
            for i in range(len(partRange)-1):
                if int(partRange[i])<a<int(partRange[i+1]):
                    partNum[i]+=1
reviewlabel=[reviewRange[i]+"-"+reviewRange[i+1] for i in range(len(reviewRange)-1)]
partlabel=[partRange[i]+"-"+partRange[i+1] for i in range(len(partRange)-1)]
plt.pie(reviewNum,labels=reviewlabel,autopct='%2.1f%%' )
plt.show()
plt.pie(partNum,labels=partlabel,autopct='%2.1f%%' )
plt.show()
